<template>
  <div class="bpmn-container">
    <div ref="canvas"
      class="canves"></div>
  </div>
</template>

<script>
import Modeler from 'bpmn-js/lib/Modeler'


import { xmlStr } from '../until/xml'

import customPalette from '../component/palette'
import paletteEntries from '../config/paletteEntries'
import customRenderer from '../component/renderer'

export default {
  data () {
    return {
      bpmnModeler: null
    }
  },
  async mounted () {
    // // 去除默认工具栏
    const modules = Modeler.prototype._modules
    const index = modules.findIndex(it => it.paletteProvider)
    modules.splice(index, 1)

    this.bpmnModeler = new Modeler({
      container: this.$refs.canvas,
      paletteEntries,
      additionalModules: [customPalette,customRenderer]
    })

    try {
      await this.bpmnModeler.importXML(xmlStr)
      // 调整在正中间
      this.bpmnModeler.get('canvas').zoom('fit-viewport', 'auto')
      console.log('rendered')
    } catch (err) {
      console.log('error rendering', err)
    }
  }
}
</script>

<style  scoped>
  .canves {
    width: 100%;
    height: 100vh;
  }
</style>